package online.inote.modules.user.controller;

import java.util.Map;

import javax.validation.groups.Default;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import online.inote.common.annotation.AutoValid;
import online.inote.common.utils.ResultFactory;
import online.inote.common.utils.ResultFactory.ResultEnum;
import online.inote.modules.user.entity.UserEntity;
import online.inote.modules.user.valid.UserSave;
import online.inote.modules.user.valid.UserUpdate;

/**
 * <p>
 * Desc: 
 * </p>
 *
 * @author XQF SUI
 * @created 2018年9月10日 上午10:47:58
 * @version 1.0
 */
@RestController
@RequestMapping(value = "user")
public class UserController {

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	/**
	 * 
	 * <p>
	 * Desc: 
	 * </p>
	 *
	 * @author XQF SUI
	 * @created 2018年9月10日 下午8:45:52
	 * @param user
	 * @return
	 * @测试参数 {"id" : "1"}
	 */
	@AutoValid(entity = UserEntity.class, groups = {UserSave.class, Default.class})
	@PostMapping(value = "save")
	public Map<String, Object> save(@RequestBody UserEntity user) {
		logger.info("保存用户验证通过");
		return ResultFactory.createResultMap(ResultEnum.SUCCESS, user);
	}
	
	/**
	 * <p>
	 * Desc: 
	 * </p>
	 *
	 * @author XQF SUI
	 * @created 2018年9月10日 下午8:46:30
	 * @param user
	 * @return
	 * @测试参数 {"id" : "1"}
	 */
	@AutoValid(entity = UserEntity.class, groups = UserUpdate.class)
	@PostMapping(value = "update")
	public Map<String, Object> update(@RequestBody UserEntity user) {
		logger.info("更新用户验证通过");
		return ResultFactory.createResultMap(ResultEnum.SUCCESS, user);
	}
}